<template>
    <div>
        <div class="topbkimg">
            <div class="title"><span>相册</span></div>
            <img src="http://imgfile.xxkdjy.top/xiangce.jpg" alt="">
        </div>
        <div class="bottom">
            <div class="albumlist">
                <div class="albumlist-item" @click="toimglist(item)" v-for="item in albumlist">
                    <div class="album-description">
                        <span>{{ item.album_name }}</span>
                        <span>{{ item.description }}</span>
                    </div>
                    <img :src="item.album_cover">
                </div>
            </div>
        </div>
        <div class="observer">
            {{ isend ? "暂无更多" : "下拉加载更多" }}
        </div>
    </div>
</template>

<script setup>
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import { getaumble } from "@/api/imglist.js"
import { deepClone } from "@/utils/index.js"
const router = useRouter();
let albumlist = ref([])
let observers
let page = ref(1)
let pageSize = ref(8)
let isend = ref(false)
function toimglist(data) {
    router.push({
        path: '/imglist',
        query: {
            pid: data.id,
            imgurl: data.album_cover,
            title: data.album_name
        }
    });
}
onMounted(async () => {
    await loa()
    observe1()
})
async function loa() {
    let res = await getaumble({
        page: page.value,
        pageSize: pageSize.value,
    })
    if (res.data.status == 200) {
        let data = deepClone(res.data.data.data)
        albumlist.value = albumlist.value.concat(data)
    } else {
        isend.value = true
        ElNotification.warning({
            title: 'warning',
            message: '暂无数据',
            offset: 50,
        })
    }
}
/* 监视 */
function observe1() {
    let box = document.querySelector('.observer')
    observers = new IntersectionObserver(async (entries) => {
        if (entries[0].intersectionRatio > 0) {
            setTimeout(async () => {
                page.value += 1
                await loa()
                if (isend.value) {
                    observers.unobserve(box)
                }

            }, 400)
        }
    })
    observers.observe(box)
}
</script>

<style lang="scss" scoped>
.observer {
    text-align: center;
    font-size: $font-size-s;
}

.album-description {
    display: flex;
    flex-direction: column;

    width: 80%;
    position: absolute;
    top: 20%;
    left: 50%;
    transform: translate(-50%, -20%);
    border-radius: 5px;
    background-color: rgba(0, 0, 0, .2);
    padding: 5px;

    @include userTheme {
        font-family: getThemeValue("fontfamily") !important;
        color: getThemeValue("fontColor");
    }

}

.album-description span {
    font: 700;
    font-family: "djy";
    font-size: 16px;
    color: #fff;
    margin-bottom: 4px;
    cursor: pointer;

    @include userTheme {
        color: getThemeValue("fontColor");
    }
}

.title {
    position: absolute;
    top: 50%;
    left: 50%;
    color: #fff;
    transform: translate(-50%, -50%);
    font-size: 30px;
    letter-spacing: .1vmax;

    span {
        background-image: -webkit-linear-gradient(bottom, #b3a8d0, #f8d3a0, #d7999c);
        -webkit-background-clip: text;
        -webkit-text-fill-color: transparent;
    }

    @include userTheme {
        font-family: getThemeValue("fontfamily");
        color: getThemeValue("fontColor");
    }

    font-weight: 700;
}

.topbkimg {
    position: relative;
    height: 40vh;
    width: 100vw;

    &::after {
        height: 100%;
        width: 100%;
        content: "";
        position: absolute;
        top: 0;
        left: 0;

        @include userTheme {
            background-color: getThemeValue("imgmask");
        }
    }
}

.topbkimg img {
    height: 100%;
    width: 100%;
    object-fit: cover;
}

.bottom {
    height: 60vh;
    width: 100vw;
    display: flex;
    justify-content: center;
    align-items: center;
    @include bk-style;
    overflow: hidden;
    padding-bottom: 20px;
}

.albumlist {
    width: 65%;

    &::-webkit-scrollbar {
        /*隐藏滚轮*/
        display: none;
    }

    @include userTheme {
        background-color: getThemeValue("albumlistColor");
        color: getThemeValue("fontColor");
    }

    border-radius: 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-around;
    margin-bottom:-14px;
    padding: 1vmax;
}

.albumlist-item img {
    height: 100%;
    width: 100%;
    object-fit: cover;
    border-radius: 10px;
}

.albumlist-item {
    height: 20vh;
    width: 15vw;
    border-radius: 10px;
    margin-bottom: 14px;
    position: relative;

}

.albumlist-item:hover {
    box-shadow: 0 3px 6px 3px rgba(7, 17, 27, .15) !important;

    transform: translateY(-3px);
}

.bk-mask:before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    display: block;
    width: 100%;
    height: 100%;
    background-color: #0000004d;
}

@media only screen and (max-width: 650px) {
    .albumlist {
        height: 100%;
        width: 80%;
        background-color: #fff;
        border-radius: 10px;
        display: flex;
        flex-direction: column;
        flex-wrap: nowrap;
        justify-content: start;
        align-items: center;
        margin-bottom: -14px;
        padding: 1vmax;
        overflow: scroll;
    }

    .albumlist-item {
        height: 20vh;
        width: 80%;
        border-radius: 10px;
        margin-bottom: 14px;
        position: relative;
    }
}</style>